package com.crazymakercircle.demo.lock.custom;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * @Description
 * @Date 2021/8/1
 * @Created by Jonathan
 */
@Slf4j
public class TestM {
    public static boolean acquired() {
        try {
            for (int i = 0; i < 3; i++) {
                log.info("hello world");
            }
            return true;
        } finally {

            log.info("finally block");
        }
    }

    // 基础知识挺多的
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            log.info("before park ret:{}", Thread.interrupted());
            LockSupport.park(Thread.currentThread());
            for (int i = 0; i < 2; i++) {
                log.info("hello world");
            }
            log.info("t1 state:{}", Thread.currentThread().getState());
            log.info("after park ret:{}", Thread.interrupted());
        });
        t1.start();
        TimeUnit.SECONDS.sleep(1);
        log.info("t1 state:{}", t1.getState());
        //t1.interrupt();
        LockSupport.unpark(t1);
        TimeUnit.SECONDS.sleep(1);
        log.info("t1 state:{}", t1.getState());
    }
}
